﻿using Abp.AspNetCore.Mvc.Controllers;
using Batman.Cms.Core.Utils;
using Batman.Jianbei.Forum.Core.Consts;
using Microsoft.AspNetCore.Mvc;
using System.Web;

namespace Batman.Jianbei.Forum.Areas.Admin
{
    [Area(RouteNames.Admin)]
    public class QrCodeController : AbpController
    {
        /// <summary>
        /// 生成绑定微信的二维码
        /// </summary>
        /// <param name="authRedirect">用户账号ID，例如: http://192.168.3.8.8080/weixin/login</param>
        /// <param name="bindPage">绑定页面(http/https开头)</param>
        /// <returns></returns>
        public IActionResult AccountBindWeixinQrCOde(string authRedirect, string callback)
        {
            //var callback = "http://192.168.31.150:8080/#/login/confirm";
            //callback = HttpUtility.UrlEncode(callback);
            //var qrcode = QrCodeUtil.GenerateUrlQrCode("http://192.168.31.150:8080/api/weixinAuth/silent?url=" + callback);

            callback = HttpUtility.UrlEncode(callback);
            var qrcodeUrl = $"{authRedirect}{callback}";
            var qrcode = QrCodeUtil.GenerateUrlQrCode(qrcodeUrl);


            return File(qrcode, "image/png");
        }
    }
}
